﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;

namespace Lawyer.Web.ActivityInfo
{
    public partial class Modify : Page
    {       

        protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string ActivityID= Request.Params["id"];
					ShowInfo(ActivityID);
				}
			}
		}
			
	private void ShowInfo(string ActivityID)
	{
		Lawyer.BLL.ActivityInfo bll=new Lawyer.BLL.ActivityInfo();
		Lawyer.Model.ActivityInfo model=bll.GetModel(ActivityID);
		this.lblActivityID.Text=model.ActivityID;
		this.txtType.Text=model.Type;
		this.txtTitle.Text=model.Title;
		this.txtDetail.Text=model.Detail;
		this.txtLawyerID.Text=model.LawyerID;
		this.txtStartDate.Text=model.StartDate.ToString();
		this.txtEndDate.Text=model.EndDate.ToString();
		this.txtFee.Text=model.Fee.ToString();
		this.txtArchiveID.Text=model.ArchiveID;
		this.txtIsArchive.Text=model.IsArchive.ToString();
		this.txtStatus.Text=model.Status.ToString();
		this.txtCreatedBy.Text=model.CreatedBy;
		this.txtCreatedDate.Text=model.CreatedDate.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtType.Text.Trim().Length==0)
			{
				strErr+="Type不能为空！\\n";	
			}
			if(this.txtTitle.Text.Trim().Length==0)
			{
				strErr+="Title不能为空！\\n";	
			}
			if(this.txtDetail.Text.Trim().Length==0)
			{
				strErr+="Detail不能为空！\\n";	
			}
			if(this.txtLawyerID.Text.Trim().Length==0)
			{
				strErr+="LawyerID不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtStartDate.Text))
			{
				strErr+="StartDate格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtEndDate.Text))
			{
				strErr+="EndDate格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtFee.Text))
			{
				strErr+="Fee格式错误！\\n";	
			}
			if(this.txtArchiveID.Text.Trim().Length==0)
			{
				strErr+="ArchiveID不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtIsArchive.Text))
			{
				strErr+="IsArchive格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtStatus.Text))
			{
				strErr+="Status格式错误！\\n";	
			}
			if(this.txtCreatedBy.Text.Trim().Length==0)
			{
				strErr+="CreatedBy不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreatedDate.Text))
			{
				strErr+="CreatedDate格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string ActivityID=this.lblActivityID.Text;
			string Type=this.txtType.Text;
			string Title=this.txtTitle.Text;
			string Detail=this.txtDetail.Text;
			string LawyerID=this.txtLawyerID.Text;
			DateTime StartDate=DateTime.Parse(this.txtStartDate.Text);
			DateTime EndDate=DateTime.Parse(this.txtEndDate.Text);
			decimal Fee=decimal.Parse(this.txtFee.Text);
			string ArchiveID=this.txtArchiveID.Text;
			int IsArchive=int.Parse(this.txtIsArchive.Text);
			int Status=int.Parse(this.txtStatus.Text);
			string CreatedBy=this.txtCreatedBy.Text;
			DateTime CreatedDate=DateTime.Parse(this.txtCreatedDate.Text);


			Lawyer.Model.ActivityInfo model=new Lawyer.Model.ActivityInfo();
			model.ActivityID=ActivityID;
			model.Type=Type;
			model.Title=Title;
			model.Detail=Detail;
			model.LawyerID=LawyerID;
			model.StartDate=StartDate;
			model.EndDate=EndDate;
			model.Fee=Fee;
			model.ArchiveID=ArchiveID;
			model.IsArchive=IsArchive;
			model.Status=Status;
			model.CreatedBy=CreatedBy;
			model.CreatedDate=CreatedDate;

			Lawyer.BLL.ActivityInfo bll=new Lawyer.BLL.ActivityInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
